<?php

	/*	
		START---------------------------------------------------------------------------------
	
		Name	: clsLayar.php
		Version	: 1.0b
		Author	: Henrik Andersen
		Company : Linnaeus University, Media Technology
		Mail	: Henrik.Andersen@lnu.se
		Date	: 2010-11-22 09:16 CET
		
		DESCRIPTION----------------------------------------------------------------------------
		
		This is the Layar class, ie the main class. For this you can assign objects, 
		actions and hotspots.
	
		SYNTAX---------------------------------------------------------------------------------
		
		The following list contains the public functions that can be used externally.
		
		Method Name:					Short Description:
		
		* setName("My Layar Name")		Set Layar Name.
		* getName()						Get Layar Name.
		* addHotspot($objHotspot)		Add a hotspot(POI) to this Layar.
		* addAction($objAction)			Add a action event to this Layar.
		* getJSON()						Get this Layar as a JSON object.
		* getArray()					Get this Layar as a associative array.
		* render()						Render this Layar as a JSON object.
		
		TO DO'S--------------------------------------------------------------------------------
		
		END------------------------------------------------------------------------------------
	*/
	
	// IMPORT
	
	require_once 'src/php/lib/QuickieLayar/Hotspot/clsHotspot.php';
	require_once 'src/php/lib/QuickieLayar/Utilities/clsUtilities.php';
	
	// PUBLIC CLASS
	
	class clsLayar
	{				
		// PUBLIC VARIABELS
		
		/*	
			All the variables are mandatory and must obtain a 
			value for the system to function properly.
		*/
				
		public $layer			= null;
		public $hotspots		= array();
		public $errorCode		= 0;
		public $errorString 	= null;
		
		/* 
			following variables are optional and do not need 
			a value in order to make the system work properly.
		*/
		
		public $nextPageKey		= null;
		public $morePages		= false;
		public $radius			= 0;
		public $refreshInterval	= 30;
		public $refreshDistance	= 100;
		public $fullRefresh		= true;
		public $actions			= array();
		public $showMessage		= null;
		public $deletedHotspots	= array();		
		
		// CONSTRUCTOR FUNCTION
		
		/*------------------------------------------------------------------------------------
		__construct:									
		This is the constructor function and it does nothing.
		------------------------------------------------------------------------------------*/
		public function __construct()
		{
			// NOTHING YET..
		}
		
		// PUBLIC FUNCTIONS
		
		/*------------------------------------------------------------------------------------
		setName:									
		A SET operation to assign a name to this Layar.
		
		!strName	String		The name of this Layar.
		------------------------------------------------------------------------------------*/
		public function setName($strName)
		{
			$this->layer = strtolower($strName);
		}
		
		/*------------------------------------------------------------------------------------
		getName:									
		A GET operation to obtain the name to this Layar.
		
		@return		String		The name of this Layar.
		------------------------------------------------------------------------------------*/
		public function getName()
		{
			return $this->layer;
		}
		
		/*------------------------------------------------------------------------------------
		addHotspot:									
		Use this public function to add a new hotspot to this Layar.
		
		!objHotspot		Object		A new hotspot object (clsHotspot.php).
		------------------------------------------------------------------------------------*/
		public function addHotspot($objHotspot)
		{
			array_push($this->hotspots, $objHotspot);
		}
		
		/*------------------------------------------------------------------------------------
		addAction:									
		Use this public function to add a new action event to this Layar.
		
		!objAction		Object		A new action object (clsAction.php).
		------------------------------------------------------------------------------------*/
		public function addAction($objAction)
		{
			array_push($this->actions, $objAction);
		}
		
		/*------------------------------------------------------------------------------------
		getJSON:									
		Use this public function to receive this Layar as a JSON object. This method can be 
		used for "rendering" of this Layar.
		
		@return		Object		A JSON object.
		------------------------------------------------------------------------------------*/
		public function getJSON()
		{
			return json_encode($this);
		}
		
		/*------------------------------------------------------------------------------------
		getArray:									
		This public function returns this Layar as an associative array. This can be useful 
		when troubleshooting or to more easily see and understand the Layar structure.
		
		@return		Array		A associative array.
		------------------------------------------------------------------------------------*/
		public function getArray()
		{
			return (array) $this;
		}
		
		/*------------------------------------------------------------------------------------
		render:									
		This function is similar getJSON, the difference is that this function requires an 
		accurate header and handles the printing of the data itself.
		
		?strCharset		String		The name of the charset used in this Layar. The default 
									is utf-8.
		------------------------------------------------------------------------------------*/
		public function render($strCharset = 'utf-8')
		{
			header("Content-type: application/json; charset=".$strCharset);
			echo $this->getJSON();
		}
	}

?>